<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="operate.*,operate.vo.*,util.Page"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
			String id = request.getParameter("id");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title></title>
            <link rel="StyleSheet" href="<%=basePath %>form/css/list.css" type="text/css" />
			<script type="text/javascript">
			function commit(){
			var pageNum=document.getElementById('pageNum').value;
			var pageCount=document.getElementById('pageCount').value;
			var regu = "^[0-9]+$";
			var re = new RegExp(regu);
			if(pageNum.search(re) == - 1){
		    	alert("请输入正整数!");
		    	return;
		    }
		    if(parseInt(pageNum)>parseInt(pageCount)){
		       alert("输入的页数不能超过总页数!");
		       return;
		    }
			window.location.href='<%=basePath%>servlet/FormServlet?method=dataList&pageNum='+pageNum+'&id=<%=id %>'
			}
			
			</script>
	</head>
	<body>
	<div class="list">
		<table class="table">
			<%
				
				Page p = (Page) request.getAttribute("page");
				List<Attr> attrs = AttrOper.findAttrsById(id);
				List<Object> datas = p.getPageList();
				out.print("<tr class='title'>");
				for (Attr attr : attrs) {
					out.print("<td>" + attr.getAname() + "</td>");
				}
				out.print("<td>操作</td>");
				out.print("</tr>");
			%>

			<%
					for (Object o : datas) {
					Map map = (Map) o;
					out.print("<tr class='data'>");
					for (Attr attr : attrs) {
						out.print("<td>" + map.get("F" + attr.getId()) + "</td>");
					}
					%>
					
					<td><a href='<%=basePath %>form/data_edit.jsp?cid=<%=id %>&id=<%=map.get("ID") %>'>修改</a></td>
					<% 
					out.print("</tr>");
				}
			%>

		</table>
		</div>
		<div>
			总共<%=p.getVisitCount()%>条数据 
			总共<%=p.getPageCount()%>页
			当前第<%=p.getPageNum()%>页
			<%
			if (p.getPageNum() > 1) {
			%><a
				href="<%=basePath%>servlet/FormServlet?method=dataList&pageNum=<%=p.getPageNum() - 1%>&id=<%=id %>">上一页</a>
			<%
			}else{
			%>
			上一页
			<%
			}
			if (p.getPageNum() < p.getPageCount()) {
			%><a
				href="<%=basePath%>servlet/FormServlet?method=dataList&pageNum=<%=p.getPageNum() + 1%>&id=<%=id %>">下一页</a>
			<%
			}else{
			%>
			下一页
			<% }%>
			<a	href="<%=basePath%>servlet/FormServlet?method=dataList&pageNum=1&id=<%=id %>">首页</a>
	    	<a	href="<%=basePath%>servlet/FormServlet?method=dataList&pageNum=<%=p.getPageCount() %>&id=<%=id %>">尾页</a>
			
			跳到第
			<input type="text" name="pageNum" id="pageNum" size="3">
			页
			<input type="button" value="跳转" onclick="commit()">
			<input id="pageCount" value="<%=p.getPageCount() %>" type="hidden">
		</div>
	</body>
</html>
